package com.wes.dsptest.camera;

import android.content.Context;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class CameraSurfaceView extends SurfaceView implements CameraViewInterface {
    private CameraSurfaceCallback mCallback;

    public CameraSurfaceView(Context context) {
        super(context);
        getHolder().addCallback(new SurfaceHolder.Callback() {
            @Override
            public void surfaceCreated(SurfaceHolder holder) {
                if (mCallback != null) {
                    mCallback.onSurfaceCreated();
                }
            }

            @Override
            public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
                if (mCallback != null) {
                    mCallback.onSurfaceChanged(width, height);
                }
            }

            @Override
            public void surfaceDestroyed(SurfaceHolder holder) {
                if (mCallback != null) {
                    mCallback.onSurfaceDestroyed();
                }
            }
        });
    }

    @Override
    public Surface getSurface() {
        return getHolder().getSurface();
    }

    @Override
    public void addCallback(CameraSurfaceCallback callback) {
        mCallback = callback;

    }

}
